<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据中心</el-breadcrumb-item>
      <el-breadcrumb-item>客户管理</el-breadcrumb-item>
      <el-breadcrumb-item>客户添加</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>添加客户</span>
        <el-button style="float: right; padding: 3px 0" icon="el-icon-close" circle @click="toList">返回</el-button>
        <el-button style="float: right; padding: 3px 50px" type="text" @click="addCustomer('AddCustomerForm')" el-icon-close>保存</el-button>
      </div>
      <div>
      </div>
      <el-form ref="form" :model="AddCustomerForm" :rules="rules"  label-width="100px">
        <el-row :gutter="100">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="名称" prop="name">
                <el-input v-model="AddCustomerForm.name"></el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="11">
            <el-form-item label="发票类型" prop="invoiceType" label-width="120px">
              <el-radio :label="0" v-model="AddCustomerForm.invoiceType">普通发票</el-radio>
              <el-radio :label="1" v-model="AddCustomerForm.invoiceType">专用发票</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="100">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="发票抬头" prop="invoiceTitle">
                <el-input v-model="AddCustomerForm.invoiceTitle"></el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="税号" prop="invoiceNum">
                <el-input v-model="AddCustomerForm.invoiceNum"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="100">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="税率" prop="taxRate">
                <el-input v-model="AddCustomerForm.taxRate"></el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="所属行业" prop="industry">
                <template>
                  <el-select v-model="AddCustomerForm.industry" placeholder="请选择">
                    <el-option
                      key="0"
                     label="机械制造"
                      :value="0">
                    </el-option>
                    <el-option
                      key="1"
                      label="房地产"
                      :value="1">
                    </el-option>
                    <el-option
                      key="2"
                      label="金融"
                      :value="2">
                    </el-option>
                    <el-option
                      key="3"
                      label="教育"
                      :value="3">
                    </el-option>
                    <el-option
                      key="4"
                      label="服务"
                      :value="4">
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="100">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="公司地址" prop="address">
                <el-input v-model="AddCustomerForm.address"></el-input>
              </el-form-item>
            </div>
          </el-col>

            <el-col :span="11">
              <el-form-item label="合作日期" prop="cooperDate">
                <el-date-picker type="date" placeholder="选择日期" v-model="AddCustomerForm.cooperDate" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>

        </el-row>

        <el-row :gutter="100">
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-form-item label="描述" prop="remarks">
                <div style="margin: 20px 0;"></div>
                <el-input
                  type="textarea"
                  placeholder="请输入内容"
                  v-model="AddCustomerForm.remarks"
                  maxlength="30"
                  show-word-limit
                >
                </el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

      </el-form>
    </el-card>

  </div>
</template>

<script>
  export default {
    name: "CustomerAdd",
    data(){
      return{
        AddCustomerForm:{},
        rules: {
          name: [
            { required: true, message: '请输入名称', trigger: 'blur' }
          ],
          invoiceTitle: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          invoiceNum: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          taxRate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          industry: [
            { required: true, message: '不能为空', trigger: 'change' }
          ],
          invoiceType: [
            { required: true, message: '请选择类型', trigger: 'change' }
          ],
          cooperDate: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'blur' }
          ]
        },
        options:[

        ]
      }
    },
    methods:{
      toList:function () {
        this.$router.push('/customer');
      },
      addCustomer:function () {
        this.$refs['form'].validate((valid) => {
          if (!valid) {
            return
          }
          this.$http.post("/customer/saveCustomer", this.AddCustomerForm).then((res) => {
              if (res.data.success) {
                this.$message({
                  message: "保存成功",
                  type: "success"
                })
                this.$router.push('/customer');
              } else {
                this.$message.error("保存失败！");
              }
            }
          )
        })
      },
      update:function (id) {
        this.$http.get("/customer/details/"+id).then((res)=>{
          this.AddCustomerForm=res.data.result;
        })
      }
    },
    mounted(){
      var id = this.$route.query.id;
      this.update(id);
    }
  }
</script>

<style scoped>

  .el-col {
    border-radius: 4px;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 1000px;
  }
</style>
